package znbkListXtfx.adapter;

import android.animation.Animator;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;
import com.example.lancooznbk.R;
import com.example.lancooznbk.utils.AnimatorHelper;
import com.example.lancooznbk.view.widget.RippleView;

import java.util.ArrayList;
import java.util.List;

import znbkListXtfx.entity.SystemReviewListEntity;


/**
 * Created by Administrator on 2018\4\24 0024.
 */

public class SrlAdapter extends BaseRecyclerAdapter<RecyclerView.ViewHolder> {

    //item类型
    public static final int ITEM_TYPE_CONTENT = 0;
    public static final int ITEM_TYPE_BOTTOM = 1;
    private LayoutInflater mLayoutInflater;
    private int mBottomCount=1;//底部View个数

    private Context mContext;
    private List<SystemReviewListEntity.ModelPaperInfoListBean> mList;
    private int mLastPosition = -1;

    public SrlAdapter(Context context) {
        this.mContext = context;
        mList = new ArrayList<>();
        mLayoutInflater = LayoutInflater.from(context);
    }





    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       if (viewType == ITEM_TYPE_CONTENT) {
            return new ContentViewHolder(mLayoutInflater.inflate(R.layout.item_rv_xtfx, parent, false));
        } else if (viewType == ITEM_TYPE_BOTTOM) {
//            return new BottomViewHolder(mLayoutInflater.inflate(R.layout.rv_footer, parent, false));
        }
        return null;
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return null;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boolean isItem) {
        if (holder instanceof ContentViewHolder) {
        } else if (holder instanceof BottomViewHolder) {
        }
    }


    @Override
    public int getAdapterItemCount() {
        return mList.size()+mBottomCount;
    }


    //内容 ViewHolder
    public static class ContentViewHolder extends RecyclerView.ViewHolder {

        public ContentViewHolder(View itemView) {
            super(itemView);

             ImageView paperImageCover;//资料封面图片
             TextView paperLastAnswerTime;
             TextView paperFinishedTotal;
             RippleView rippleLayout;
             TextView paperInduction;//资料简介
             TextView paperTotal;//资料试题数量
             ProgressBar progressBar;//资料进度显示
             LinearLayout paperInto;
             TextView tvIntoDetail;

            rippleLayout = (RippleView) itemView.findViewById(R.id.item_ripper);
            paperImageCover = (ImageView) itemView.findViewById(R.id.img_paper);
            paperInduction = (TextView) itemView.findViewById(R.id.tv_induction);
            paperLastAnswerTime = (TextView) itemView.findViewById(R.id.tv_lastTime);
            paperTotal = (TextView) itemView.findViewById(R.id.tv_total);
            paperFinishedTotal = (TextView) itemView.findViewById(R.id.tv_answered);
            progressBar = (ProgressBar) itemView.findViewById(R.id.pb_finished);
            paperInto = (LinearLayout) itemView.findViewById(R.id.liner_into);
            tvIntoDetail = (TextView) itemView.findViewById(R.id.tv_into_detail);


//            int adapterPosition = getAdapterPosition();
//            boolean isScrollDown = adapterPosition > mLastPosition;
//            for (Animator anim : AnimatorHelper.getRecyclerAnimator(itemView,isScrollDown)) {
//                anim.start();
//            }
//            mLastPosition = adapterPosition;

        }

    }

    //底部 ViewHolder
    public static class BottomViewHolder extends RecyclerView.ViewHolder {
        public BottomViewHolder(View itemView) {
            super(itemView);


//              /*
//           * 主界面学习模块按钮
//           * 笔记列表
//           * */
//            LinearLayout mLayoutNotes;
//            mLayoutNotes = (LinearLayout) itemView.findViewById(R.id.layout_notes);
//            mLayoutNotes.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Intent intent=new Intent(mContext, NotesListActivity.class);
//                    mContext.startActivity(intent);
//                }
//            });
//
//            /*
//           * 主界面学习模块按钮
//           * 收藏列表
//           * */
//            LinearLayout mLayoutCollection;
//            mLayoutCollection = (LinearLayout) itemView.findViewById(R.id.layout_collection);
//            mLayoutCollection.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Intent intent=new Intent(mContext, CollectionListActivity.class);
//                    mContext.startActivity(intent);
//                }
//            });


        }

    }


    public void clearAndAdd(List<SystemReviewListEntity.ModelPaperInfoListBean> data){
        mLastPosition = -1;
        mList.clear();
        mList.addAll(data);
        notifyDataSetChanged();
    }
    public void add(List<SystemReviewListEntity.ModelPaperInfoListBean> data){
        int startPosition = getStart()+getAdapterItemCount();
        mList.addAll(data);
        notifyItemRangeInserted(startPosition,data.size());

    }

}
